package com.javasvip.serviceuser.service.impl;

import com.javasvip.common.pojo.Token;
import com.javasvip.serviceuser.dao.LagouTokenDao;
import com.javasvip.serviceuser.service.TolenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TolenServiceImpl implements TolenService {

    @Autowired
    com.javasvip.serviceuser.dao.LagouTokenDao LagouTokenDao;

    @Override
    public Token fToken(Long id) {

        List<Token> all = LagouTokenDao.findAll();
        System.out.println("all"+all);
        return null;
    }

    /**
     * 登录
     * @param email
     * @param token
     * @return
     */
    @Override
    public Token login(String email, String token) {
        List<Token> login = LagouTokenDao.login(email, token);
        if (login!=null && login.size()==1){
            System.out.println("登录成功");
            return login.get(0);
        }else {
            System.out.println("用户名或者密码不正确");
            return null;
        }
    }

    /**
     * 注册
     * @param token
     */
    @Override
    public boolean save(Token token) {
        List<Token> login = LagouTokenDao.login(token.getEmail(),token.getToken());
        if(login==null || login.size()==0){
            LagouTokenDao.save(token);
            System.out.println("注册成功");
            return true;
        }else {
            System.out.println("用户已存在");
            return false;
        }

    }
}
